package com.red.star.macalline.data.mappers;

import com.red.star.macalline.data.core.base.MyMapper;
import com.red.star.macalline.data.entity.Employee;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface EmployeeMapper extends MyMapper<Employee> {
    List getEmployeeByMerchantId(String merchantId);

    List<Employee> getEmployeeListByGroupId(Integer groupId);

    List<Employee> getEmployeeByVipOpenId(String vipOpenId);

    List<Employee> getEmployeeByFansId(Integer fansID);

    List<Employee> getEmployeeByMallCode(String mallCode);

    List<Employee> getEmployeeByParam(Employee employee);

    public void updateEmployee(Employee employee);

    @Update(value = "update t_employee set status =2 where id = #{id}")
    public void deleteEmployeeById(Integer id);

    void updateEmployeeByParam(Employee employee);

    List<Employee> getAllEmployeeList(Employee employee);

    @Select(value = "select * from t_employee where vip_open_id = #{vipOpenId} and status = 0")
    Employee getEmployeeByVipOpenIdAndStatusO(String vipOpenId);

    @Select(value = "select * from t_employee t where t.vip_open_id = #{vipOpenId} and status = 0")
    public Employee findEmployeeByVipOpenid(String vipOpenId);

    @Select(value = "select * from t_employee where fans_id = #{fansId} and status = 0 limit 1")
    Employee getEmployeeBybFansIdAndStatusO(Integer fansId);

    @Select(value = "select * from t_employee t where t.fans_id = #{fansId} and status = 0")
    public Employee findEmployeeByFansId(Integer fansId);

    @Select(value = "select * from t_employee t where t.vip_id = #{vipId}")
    public Employee findEmployeeByVipId(String vipId);

    //条件：1、status为0 2、merchant_id不为空且为当前导购员的一致 3、不包含当前导购员 4、type为0
    @Select(value = "select * from t_employee t where t.status = 0 and merchant_id = #{merchantId} and " +
            "t.type = 0 and id <> #{employeeId} and t.is_shop_owner = 1")
    public Employee findEffectiveEmployee(@Param("merchantId") Integer merchantId, @Param("employeeId") Integer employeeId);

    //条件：1、status为0 2、merchant_id不为空且为当前导购员的一致 4、type为0
    @Select(value = "select * from t_employee t where t.status = 0 and merchant_id = #{merchantId} and " +
            "t.type = 0 and t.is_shop_owner = 1")
    Employee findEffectiveEmployeeOther(@Param("merchantId") Integer merchantId);

    public void changeEmployeeById(@Param("id") Integer id, @Param("isShopOwner") Boolean isShopOwner);

    public void changeEmployeeByNameAndMobile(@Param("employeeName") String employeeName, @Param("employeeMobile") String employeeMobile, @Param("isShopOwner") Boolean isShopOwner);

    List<Employee> selectEmployeeListByParamNew(Employee employee);

    Employee findEmployeeSetting(@Param("mallCode") String mallCode);

    @Select("SELECT id, fans_id, name FROM t_employee WHERE is_customer = 1 AND `status` = 0 AND type = 1 AND mall_code = #{mallCode}")
    List<Employee> listEmployeeByMallCode(@Param("mallCode") String mallCode);

    Employee findEmployeeByMobile(@Param("mobile") String mobile,@Param("mallCode") String mallCode);

    public void updateEmployeeIsCustomerById(@Param("id") Integer id, @Param("isCustomer") Integer isCustomer, @Param("priority") Integer priority);

    public void updateEmployeeIsCustomerByMallCode(@Param("mallCode") String mallCode);

    @Select("select id, fans_id from t_employee where status = 0 and type = 0 and mall_code = #{mallCode}")
    List<Employee> findEmployeeByMallCode(@Param("mallCode") String mallCode);

    @Select("select * from t_employee where status = 0 and type = 0")
    List<Employee> findAllEmployee();
}
